/* 产引入jsencrypt实现数据RSA加密 */
import JSEncrypt from 'jsencrypt' // 处理长文本数据时报错 jsencrypt.js Message too long for RSA
/* 产引入encryptlong实现数据RSA加密 */
import Encrypt from 'encryptlong' // encryptlong是基于jsencrypt扩展的长文本分段加解密功能。

// 密钥对生成 http://web.chacuo.net/netrsakeypair

// 公钥key
const publicKey = "-----BEGIN PUBLIC KEY-----\n" +
    "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDdq/k5z3vaBL1VCpju+B5nMIufm//4Ut/J3z8Y+di7LPF+EYJ7GOss9+lEV1ligUjxtbXcSHT8EXUh4CWIJyriei9ck/dxaMhppnBe+QnkAUUlOWlsiFtRE1dCP8MQxesE9SsWHdjsGqJW1+hS/ZN3lUIiPIVnYJIDqsVZW0WS6QIDAQAB\n" +
    "-----END PUBLIC KEY-----"

// 私钥key
const privateKey = "-----BEGIN PRIVATE KEY-----\n" +
    "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAN2r+TnPe9oEvVUKmO74Hmcwi5+b//hS38nfPxj52Lss8X4RgnsY6yz36URXWWKBSPG1tdxIdPwRdSHgJYgnKuJ6L1yT93FoyGmmcF75CeQBRSU5aWyIW1ETV0I/wxDF6wT1KxYd2OwaolbX6FL9k3eVQiI8hWdgkgOqxVlbRZLpAgMBAAECgYAkNj3GdeCTowaS5+JH13yP+tw0PLW6CT/JqJCUMex310W0BIQ+O7nfZLhUk7hkYR5bbgXBcIy7yNZLrGQ1M8DLZLmo4FRoR2fV05PI9+NXt/In+Q93mp77nR3HQnIBsLO+VNnHI3OL1kcOyMWs1GzaaGpllGXCy0dtTlTPEQ0aSQJBAO6lEbYjnqS35+ThIy4KTfKMaIgykvQe54Ze7YdV2lL4I9NIt83CuQyMpAmm/+D/inStN4fSLYnenUrSQVlzvIsCQQDtyulm9Hjo4s5JuQS1Oy8P99GDptZG8F35l5Mf+3wccwWnybEQ8XCn9boUNc8FMxx9e9t6nDG7SuQoIvrKStjbAkAiJSoolmYfiVS7sd7Xuo+2kZJvUlUmarmTx0dTItyPHIP7uh7aaO8TNZhO7T8VUVrdIN+eJltvq5Nz3iuNgfrLAkEAyn0SebBOUYnpPhAGOUl3jvJpf+EO8IN4krSG/SIKkrNDqphuZk4ir3PpC5Kygev/I7/XqrXdB28DkEYRJzfLJwJBAK9bemX0od6glxuq0WlUxFcsiKBS7CCp6WT+EdhpGDrw+34CnqE8MzkXaFiFcJoSI73MG+KmnSWvTunHM6I/SQU=\n" +
    "-----END PRIVATE KEY-----"

export default {
    RSAencrypt(pas) {
        //实例化jsEncrypt对象
        let jse = new JSEncrypt();
        //设置公钥
        jse.setPublicKey(publicKey);
        //  console.log('加密：' + jse.encrypt(pas))
        return jse.encrypt(pas);
    },

    //解密方法
    RSAdecrypt(pas) {
        let jse = new JSEncrypt();
        // 私钥
        jse.setPrivateKey(privateKey)
        // console.log('解密：' + jse.decrypt(pas))
        return jse.decrypt(pas);
    },
}